# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=opam-monorepo
pkgver=0.4.0
pkgrel=0
pkgdesc="Opam plugin that assembles a self-contained Dune workspace based on a precise lock file"
url="https://github.com/tarides/opam-monorepo"
arch="all"
license="ISC"
depends="opam"
makedepends="dune ocaml-compiler-libs"
checkdepends="git rsync"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.bz2::https://github.com/tarides/opam-monorepo/releases/download/$pkgver/opam-monorepo-$pkgver.tbz"

case "$CARCH" in
	riscv64|loongarch64)
		makedepends="${makedepends//ocaml/ocaml5}"
		;;
esac

export OPAMROOT="${OPAMROOT:-"$srcdir/opam-root"}"
export OPAMLOGS="${OPAMLOGS:-"$srcdir/opam-logs"}"

_opam_opts="-v -y --cli=2.2 --no-self-upgrade"

prepare() {
	default_prepare

	if want_check && [ ! -f "$OPAMROOT"/config ]; then
		opam init $_opam_opts \
			--compiler=ocaml-system \
			--disable-sandboxing \
			--no-setup
	fi
}

build() {
	dune build --release --verbose
}

check() {
	export GIT_AUTHOR_NAME="test"
	export GIT_COMMITTER_NAME="test"
	export GIT_AUTHOR_EMAIL="test@example.com"
	export GIT_COMMITTER_EMAIL="test@example.com"

	dune runtest --build-dir=.testenv
}

package() {
	dune install --destdir="$pkgdir"
}

sha512sums="
ced42bab2ce2bdf1d832dae06f472eb8bf18c7c41bab7d77ec13f663e2fd69ad5602e45145e952f8f1f72613cac9c6a8ad6e2f43f5f58265374df9247a015c53  opam-monorepo-0.4.0.tar.bz2
"
